﻿(function() {
    nova.widgets.ToastOption = function() {
        this.showDuration = 500;
        this.displayDuration = 2000;
        this.hideDuration = 500;
        this.css = "";
    };

    nova.widgets.toast = function (message, options) {
        if (options) {
            options = $.extend(new nova.widgets.ToastOption(), options);
        } else {
            options = new nova.widgets.ToastOption();
        }

        var $toast = $("<div class='toast'>" + message + "</div>");
        if (options.css != "") {
            $toast.addClass(options.css);
        }
        $toast.appendTo("#body");
        var centerX = $(window).width() / 2;
        var left = centerX - $toast.width() / 2;
        var bottom = $(window).height() / 10;
        $toast.css("bottom", 0 + "px");
        $toast.css("left", left + "px");
        $toast.animate({
            bottom: "+=" + bottom,
            opacity: 1
        }, {
            duration: options.showDuration,
            complete: function () {
                setTimeout(function () {
                    $toast.animate({
                        bottom: "-=35",
                        opacity: 0
                    }, {
                        duration: options.hideDuration,
                        complete: function () {
                            $toast.remove();
                        }
                    });
                }, options.displayDuration);
            }
        });
    };
})();

